﻿using System;
using System.IO;

namespace CabConfigProvisioning
{
    public class CabCreate : FciFunctions
    {

        private FileInfo _cabFile;

        public CabCreate(FileInfo cabFile)
        {
            SetDelegates();
            _cabFile = cabFile;
            CreateContext(cabFile.FullName);
        }

        public void Add(string sFilePath, string sResourcePath)
        {
            if (!FciAddFile(_hContext, sFilePath, sResourcePath, false, _getNextCabinetDelegate, _statusDelegate, _getOpenInfoDelegate, COMP_MSZIP))
                throw new ApplicationException();
        }

        public void FlushFolder()
        {
            if (!FciFlushFolder(_hContext, _getNextCabinetDelegate, _statusDelegate))
                throw new ApplicationException();
        }

        public override void Dispose()
        {
            if(!_bDisposed)
            {
                if (!FciFlushCabinet(_hContext, false, _getNextCabinetDelegate, _statusDelegate))
                    throw new ApplicationException();
            }
        }

    }
}
